<?php

class QuickLinks
{
    const PATH_IMAGES = '/images/';

    public static function Generate( $pageId )
    {
        $result = "";
        $tmpl = Core::CreateTemplateEngine( PATH_TEMPLATES . 'include/menu/quick_links/' );
        
        $tmpl->set('ITEMS', '');
        
        $items = Pages::GetQuickLinks($pageId);
        $count = count($items);
        for ( $i = 0; $i < $count; $i++ )
        {
            $tmpl->clearAll();

            $tmpl->define('link_item', 'link_item.tpl');
            $tmpl->define('text_item', 'text_item.tpl');

            $item = $items[$i];
            $tmpl->set('TEXT', $item->name);
            if ( $item->link )
            {
                $page = Pages::GetPageInfo($item->pageId);
                $pagePath = $page->GetUrl();
                $pagePath = empty($item->anchor) ? $pagePath : $pagePath . '#' . $item->anchor;

                $tmpl->set('LINK', $pagePath);
                $tmpl->set('LANG', $page->language);
                $tmpl->set('ICON', self::PATH_IMAGES . $page->icon);
                $tmpl->set('CLASS', ($i == $count - 1) ? 'last_link' : '');
                $tmpl->set('LINK_CLASS', $item->class);
                $tmpl->set('LINK_TARGET', $item->target);
                $tmpl->parse('ITEMS', '.link_item');
            }
            else
            {
                $tmpl->set('TEXT_CLASS', $item->class);
                $tmpl->parse('ITEMS', '.text_item');
            }

            $result .= $tmpl->getGenerated() . "\n";
        }

        return $result;
    }
}

?>